#include "protocol.h"
struct  frame_ctl_s frame_ctl;
protocol::protocol()
{

}
void protocol::run()
{
    frame_ctl.frame_head_pos =0;
    frame_ctl.frame_buf_state = FRAME_BUF_HEAD;
    while (1) {
            //取出数据进行判断。
            if(serial_recv_buf.head == serial_recv_buf.tail){//刚开始是空的
                continue;
            }
            if((serial_recv_buf.head )%SERIAL_BUF_LEN != serial_recv_buf.tail){
                if(frame_ctl.frame_head_pos <(FRAME_CTL_LEN_SIZE)){    //刚开始数组还没满。
                    frame_ctl.frame_head[frame_ctl.frame_head_pos] = serial_recv_buf.data[serial_recv_buf.head];
                    serial_recv_buf.head = (serial_recv_buf.head +1)%SERIAL_BUF_LEN;
                    frame_ctl.frame_head_pos++;
                    qDebug()<<"array is not full";
                }
                else {   //后面数组满了。
                    memcpy(frame_ctl.frame_head,frame_ctl.frame_head+1,FRAME_CTL_LEN_SIZE-1);
                    frame_ctl.frame_head[FRAME_CTL_LEN_SIZE-1] = serial_recv_buf.data[serial_recv_buf.head];
                    serial_recv_buf.head = (serial_recv_buf.head +1)%SERIAL_BUF_LEN;
                     qDebug()<<"array is  full";
                }
            }
    }
}
